package cn.laike.modules.wechat.service.impl;

import java.util.Map;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;

import cn.laike.common.utils.PageUtils;
import cn.laike.common.utils.Query;
import cn.laike.modules.wechat.dao.WechatDao;
import cn.laike.modules.wechat.entity.WechatEntity;
import cn.laike.modules.wechat.service.WechatService;


@Service("wechatService")
public class WechatServiceImpl extends ServiceImpl<WechatDao, WechatEntity> implements WechatService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        Page<WechatEntity> page = this.selectPage(
                new Query<WechatEntity>(params).getPage(),
                new EntityWrapper<WechatEntity>()
                .eq("status", "1")
                .orderBy("id", false)
        );

        return new PageUtils(page);
    }

	@Override
	public WechatEntity getWechatEntity(Long uid) {
		return this.selectOne(new EntityWrapper<WechatEntity>().eq("uid", uid));
	}

	@Override
	public WechatEntity getWechatEntity(String authorizerAppid) {
		return this.selectOne(new EntityWrapper<WechatEntity>().eq("authorization_appid", authorizerAppid));
	}

	@Override
	public WechatEntity getWechatByUserName(String userName) {
		return this.selectOne(new EntityWrapper<WechatEntity>().eq("user_name", userName));
	}

}
